package frame;

import util.Util;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LookPanel extends JPanel implements ActionListener {
    private ATM atm;
    private JButton sureBtn;
    private JButton clearBtn;
    private Icon sureImg = Util.getImageIcon("/images/buttonSure.jpg");
    private Icon clearImg = Util.getImageIcon("/images/buttonOff.jpg");
    private JLabel inbalance = new JLabel();


    public LookPanel(ATM atm) {
        this.atm = atm;
        this.setLayout(null);
        this.setOpaque(false);

        JLabel balance = new JLabel("您的余额为：");
        balance.setBounds(220, 200, 100, 30);
        balance.setFont(new Font("黑体", Font.BOLD, 16));
        this.add(balance);

        inbalance.setBounds(340, 200, 100, 30);
        inbalance.setFont(new Font("黑体", Font.BOLD, 16));
        this.add(inbalance);

        sureBtn = new JButton(sureImg);
        sureBtn.setBounds(220, 240, 140, 50);
        this.add(sureBtn);
        sureBtn.addActionListener(this);

        clearBtn = new JButton(clearImg);
        clearBtn.setBounds(380, 240, 140, 50);
        this.add(clearBtn);
        clearBtn.addActionListener(this);
    }

    public void setBlance(double blance){
        inbalance.setText(blance + "");
    }

    public JLabel getInbalance() {
        return inbalance;
    }

    public void setInbalance(JLabel inbalance) {
        this.inbalance = inbalance;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == sureBtn) {
            atm.switchPanel("menu");
        } else if (e.getSource() == clearBtn) {
            atm.switchPanel("login");
        }
    }
}

